/****************************************************
	文件：HotPatchWindow.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2021/1/24 9:54:14
	功能：热更窗口
*****************************************************/

using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEditor;
using HTFW.Consts;
using HTFW.Utility;
using HTFW.Utility.Editor;

namespace HTFW
{
    public class HotPatchWindow : EditorWindow
    {
        [MenuItem(MenuPath.HOT_PATCH_WINDOW_PATH, false, 7)]
        static void Init()
        {
            HotPatchWindow window =
                (HotPatchWindow) EditorWindow.GetWindow(typeof(HotPatchWindow), false, "热更包界面", true);
            window.Show();
        }

        string mMd5Path = "";
        string mHotCount = "1";
        OpenFileName mOpenFileName = null;

        private void OnGUI()
        {
            GUILayout.BeginHorizontal();
            mMd5Path = EditorGUILayout.TextField("ABMD5路径： ", mMd5Path, GUILayout.Width(350), GUILayout.Height(20));
            if (GUILayout.Button("选择版本ABMD5文件", GUILayout.Width(150), GUILayout.Height(30)))
            {
                mOpenFileName = new OpenFileName();
                mOpenFileName.structSize = Marshal.SizeOf(mOpenFileName);
                mOpenFileName.filter = "ABMD5文件(*.bytes)\0*.bytes";
                mOpenFileName.file = new string(new char[256]);
                mOpenFileName.maxFile = mOpenFileName.file.Length;
                mOpenFileName.fileTitle = new string(new char[64]);
                mOpenFileName.maxFileTitle = mOpenFileName.fileTitle.Length;
                mOpenFileName.initialDir = (Application.dataPath + "/../Version").Replace("/", "\\"); //默认路径
                mOpenFileName.title = "选择MD5窗口";
                mOpenFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;
                if (LocalDialog.GetSaveFileName(mOpenFileName))
                {
                    Debug.Log(mOpenFileName.file);
                    mMd5Path = mOpenFileName.file;
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            mHotCount = EditorGUILayout.TextField("热更补丁版本：", mHotCount, GUILayout.Width(350), GUILayout.Height(20));
            GUILayout.EndHorizontal();
            if (GUILayout.Button("开始打热更包", GUILayout.Width(100), GUILayout.Height(50)))
            {
                if (!string.IsNullOrEmpty(mMd5Path) && mMd5Path.EndsWith(".bytes"))
                {
                    //BundleEditor.Build(true, md5Path, hotCount);
                }
            }
        }
    }
}